local skel = fk.CreateSkill({
  name = "lb__zaiyun",
  tags = {Skill.Compulsory}
})

Fk:loadTranslationTable {
  ["lb__zaiyun"] = "灾孕",
  --[":lb__zaiyun"] = "<b>锁定技</b>，当你受到伤害后，你摸三张牌，然后你可以将一张牌置于武将牌上，称为「<b>卵</b>」。准备阶段，你可以将所有「<b>卵</b>」当目标数至多为选择「<b>卵</b>」数的【南蛮入侵】使用。",
  --10.15
  [":lb__zaiyun"] = "<b>锁定技</b>，当你受到伤害后，你摸三张牌并获得一个“<b>卵</b>”。准备阶段，你可以移除所有“<b>卵</b>”，视为使用目标数至多为移除“<b>卵</b>”数的【南蛮入侵】。",

  ["#lb__zaiyun"] = "灾孕：你可以移除所有“<b>卵</b>”，视为使用至多指定%arg个目标的【南蛮入侵】",
  --["#lb__zaiyun"] = "灾孕：你可以将所有「<b>卵</b>」当至多指定%arg个目标的【南蛮入侵】使用",
  --["#lb__zaiyun_put"] = "灾孕：你可以将一张牌置于武将牌上，称为「<b>卵</b>」",

  --["lb__zaiyun__luan"] = "卵",
  ["@lb__zaiyun__luan"] = "卵",

  ["$lb__zaiyun1"] = "",
  ["$lb__zaiyun2"] = "",
}


skel:addEffect(fk.Damaged, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(3, "lb__zaiyun")
    room:addPlayerMark(player, "@lb__zaiyun__luan")
    --[[
    if not player:isNude() then
      local cards = room:askToCards(player, {
        min_num = 1,
        max_num = 1,
        skill_name = "lb__zaiyun",
        cancelable = true,
        include_equip = true,
        prompt = "#lb__zaiyun_put"
      })
      if #cards > 0 then
        player:addToPile("lb__zaiyun__luan", cards, true, "lb__zaiyun", player)
      end
    end
    --]]
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    --local cards = player:getPile("lb__zaiyun__luan")
    if target == player and player:hasSkill(skel.name) and player:getMark("@lb__zaiyun__luan") > 0 then
      local card = Fk:cloneCard("savage_assault")
      --card:addSubcards(cards)
      card.skillName = "lb__zaiyun"
      return table.find(player.room:getOtherPlayers(player), function(to)
        return player:canUseTo(card, to)
      end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --local cards = player:getPile("lb__zaiyun__luan")
    local card = Fk:cloneCard("savage_assault")
    --card:addSubcards(cards)
    card.skillName = "lb__zaiyun"
    local tos = table.filter(player.room:getOtherPlayers(player), function(to)
      return player:canUseTo(card, to)
    end)
    --local num = math.min(#cards, #tos)
    local num = math.min(player:getMark("@lb__zaiyun__luan"), #tos)
    tos = room:askToChoosePlayers(player, {
      targets = tos,
      max_num = num,
      min_num = 1,
      skill_name = "lb__zaiyun",
      cancelable = true,
      prompt = "#lb__zaiyun:::" .. num,
    })
    if #tos > 0 then
      room:sortByAction(tos)
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local tos = event:getCostData(self).tos
    --player.room:useVirtualCard("savage_assault", player:getPile("lb__zaiyun__luan"), player, tos, "lb__zaiyun")
    player.room:setPlayerMark(player, "@lb__zaiyun__luan", 0)
    player.room:useVirtualCard("savage_assault", nil, player, tos, "lb__zaiyun")
  end,
})

return skel